import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { User } from '../domain/user';

import { UserService } from '../service/user.service';

@Component({
  selector: 'app-sign-up',
  templateUrl: './sign-up.component.html',
  styleUrls: ['./sign-up.component.css'],
  providers: [UserService]
})
export class SignUpComponent implements OnInit {

  user = new User();

  constructor(private userService: UserService,
    private router: Router) { }

  ngOnInit() {
  }

  onSubmit() {
    this.userService.createUser(this.user)
      .then(user => {
        this.router.navigate(['/index']);
      });
    this.user.username = "";
    this.user.password = "";
    this.user.room = "";
  }
}
